/*
 *
 * Test cases for broomie
 *
 * This test case is using google test framework.
 * website: http://code.google.com/p/googletest/
 *
 * (Assertion samples)
 *   ASSERT_TRUE(condition)      : condition is true
 *   ASSERT_FALSE(condition)     : condition is false
 *   ASSERT_EQ(expected, actual) : expected == actual
 *   ASSERT_NE(val1, val2)       : val1 != val2
 *   ASSERT_LT(val1, val2)       : val1 < val2
 *   ASSERT_LE(val1, val2)       : val1 <= val2
 *   ASSERT_GT(val1, val2)       : val1 > val2
 *   ASSERT_GE(val1, val2)       : val1 >= val2
 *
 */

#include <iostream>
#include <gtest/gtest.h>
#include <libpocketj.hpp>

const std::string DB_PATH = "./db/";

namespace pocketj {

  class POCKETJTestCase : public ::testing::Test {
  public:
    pocketj::Analyzer* anal;

  protected:
    virtual void SetUp()
    {
      double threshold = 0.2;
      double param = 2.5;
      std::string dbPath = "./db/";
      anal = new pocketj::Analyzer(threshold, 2.5, dbPath);
    }

    virtual void TearDown()
    {
      delete anal;
    }
  };

  TEST_F(POCKETJTestCase, allTest)
  {
    for (int i = 0; i < 5000; i++) {
      std::string key = pocketj::util::createRandomString();
      std::cerr << "add doc:" << i << "\t" << key << std::endl;
      ASSERT_TRUE(anal->addDoc(i, key));
    }

    for (int i = 0; i < 5000; i++) {
      std::string key = "abcde";
      ASSERT_FALSE(anal->addDoc(i, key));
    }

    std::string testKey = "aaaaaaaaaaaaaaaaaaaaaaaaaaaa";
    ASSERT_TRUE(anal->addDoc(5000, testKey));
    ASSERT_TRUE(anal->addDoc(5001, testKey));
    ASSERT_TRUE(anal->addDoc(5002, testKey));

    anal->sortDoc();

    std::map<int, std::set<int> > result;
    ASSERT_TRUE(anal->doJoin(result));
    ASSERT_GT(result.size(), 2);
  }

  TEST(pocketj, getNgram)
  {
    std::vector<std::string> ngram;
    std::string text = "abcdef";
    pocketj::util::getNgram(ngram, text, 3);
    for (unsigned int i = 0; i < ngram.size(); i++) {
      std::string hoge = ngram.at(i);
      std::cerr << hoge << std::endl;
    }
  }
}

int main(int argc, char** argv)
{
  ::testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}
